package com.zee.activity

//import com.zee.activity.SampleApplicationLike.showNotification
import TestPresenter
import android.Manifest
import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.support.v7.app.AppCompatActivity
import android.widget.RemoteViews
import com.zee.activity.ui.NotificationHelper
import com.zee.activity.ui.ToastActivity
import com.zee.listener.OnPermissionListener
import com.zee.log.ZLog
import com.zee.notification.NotificationAdapter
import com.zee.notification.NotificationBean
import com.zee.toast.ToastUtils
import com.zee.utils.SuperZPerMissionUtils
import com.zee.utils.ZEventBusUtils
import com.zee.utils.ZLibrary
import kotlinx.android.synthetic.main.activity_main.*
import org.greenrobot.eventbus.SubscribeMainThread

//import java.util.ArrayList


class MainActivity : AppCompatActivity() {

    private val PERMISSIONS1 = listOf(
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.FOREGROUND_SERVICE
    )
    var index = 1;
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        ZLibrary.init(application, true);
        setContentView(R.layout.activity_main)
        ZEventBusUtils.register(this)

        val preferencesUtils = SuperZPerMissionUtils.getInstance()
        preferencesUtils.addAll(PERMISSIONS1);
        preferencesUtils.requestPermissions(object : OnPermissionListener {
            override fun onPerMission(permissions: List<String>, permissionText: List<String>) {
                if (permissions.isEmpty()) {

                } else {

                }
            }
        }, this)

//        MyDialog.newDefaultMyDialog(R.layout.dialog_mid)

//        MyDialog.newDefaultMyDialog(R.layout.dialog_mid).setMarginLeftAndRight(20).setBindViewAdapter(object : BindViewAdapter() {
//            fun initViews(paView: View) {
//                setText(R.id.id_mid_value_view, "设置上值")
//            }
//        }).show(supportFragmentManager)

        id_activity_bannerView.setOnClickListener {

//        UIUtils.getCurActivity().finish();
            val bean = NotificationBean()

//            val intent = Intent(this, CrashActivity::class.java)
//            intent.putExtra("txt", "message")
            bean.setContentActivity(CrashActivity::class.java)
            bean.setAdapter(object : NotificationAdapter() {
                override fun getLayoutResID(): Int {
                    return R.layout.notification_mobile_play
                }

                override fun initViews(parentView: RemoteViews) {
                    setText(R.id.tv_title, "北京")
                    setText(R.id.tv_artist, "科技公司")
                }
            })
            bean.sendNotification(index++, "Crash", "info", com.zee.libs.R.drawable.ic_lib_zee)

//            startActivity(BannerViewActivity::class.java)
        }

        id_show_toast_activity.setOnClickListener {
//            startActivity(ImagePickerMainActivity::class.java)
//            startActivity(ToastActivity::class.java)
        }

        id_show_Route.setOnClickListener {
            showToast2()
            //            val view = LayoutInflater.from(this).inflate(R.layout.add_view_test, id_root, true);
//            id_root.addView(view);
//            startActivity(RouteActivity::class.java)
        }
        id_click_permission.setOnClickListener {
            //申请权限
            NotificationHelper.show(this);
//            SampleApplicationLike.showNotification(applicationContext, "title", "message", MainActivity::class.java)
//            startActivity(PermissionRequestActivity::class.java)
        }

        ZLog.i("输出成功 ")
        ZLog.i("Tag", "输出成功")
        ZLog.i("显示当前---》》", true)

        test2()
//        id_show_callBack.setOnClickListener {
//            id_show_callBack.isSelected = !id_show_callBack.isSelected
//            if (id_show_callBack.isSelected) {
//                id_show_callBack.setText("选中状态")
//            } else {
//                id_show_callBack.setText("取消选中状态")
//            }
////            startActivity(CallbackActivity::class.java)
//        }

    }

//    fun test20(){
//        OrderWorkManager().addWork { work -> work.workFinish() }.addWork { }.addWork { }.startWork()
//    }

    fun showToast2() {
        showToast3()
    }

    fun showToast3() {
//        post(1, "测试看看")
    }

    private fun startActivity(aClass: Class<*>) {
        val intent = Intent(this, aClass)
        startActivity(intent)
    }

    @SubscribeMainThread(tag = "测试看看")
    public fun initTitle(value: Int) {
        ToastUtils.showToastShort("测试显示出来")
//        test2()
        ZLog.i("打印栈信息--->>打印Eventbus日志", true)
    }

    @SubscribeMainThread(tag = "测试看看")
    public fun initTitle2(value: Int) {
        ZLog.i("没有打印栈信息--》打印Eventbus日志")
    }


    @SubscribeMainThread(tag = "2")
    public fun initTitle2(value: String) {
    }

    fun testGitBranch() {
        ZLog.i("分支测试", true);
    }


    fun test2() {
        test3()
    }

    fun test3() {
        ZLog.i("测试堆栈信息", true)
        ZLog.i("打印Eventbus日志")
    }

    override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?) {
        super.onSaveInstanceState(outState, outPersistentState)
        ZLog.i("onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?)")
    }

    override fun onSaveInstanceState(outState: Bundle?) {
        super.onSaveInstanceState(outState)
        ZLog.i("onSaveInstanceState(outState: Bundle?)")
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
        super.onRestoreInstanceState(savedInstanceState)
        ZLog.i("onRestoreInstanceState(outState: Bundle?)")
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onRestoreInstanceState(savedInstanceState, persistentState)
        ZLog.i("onRestoreInstanceState(outState: Bundle?)")

    }


    override fun onDestroy() {
        super.onDestroy()

        ZEventBusUtils.unregister(this)
    }
}
